//
//  RecommendTableViewController.swift
//  beegin2
//
//  Created by zsy on 16/3/19.
//  Copyright © 2016年 kszz. All rights reserved.
//

import UIKit

class RecommendTableViewController: UITableViewController {
    
    let recommendContent:(summary:String,over:String,lack:String,suply:String) = ("维生素A（vitaminA）又称视黄醇（其醛衍生物视黄醛）或抗干眼病因子，是一个具有脂环的不饱和一元醇，包括动物性食物来源的维生素A1、A2 两种，是一类具有视黄醇生物活性的物质。维生素A1多存于哺乳动物及咸水鱼的肝脏中，而维生素A2常存于淡水鱼的肝脏中。由于维生素A2的活性比较低，所以通常所说的维生素A是指维生素A1。\n\n维生素A在分类中属于脂溶性维生素，同属于脂溶性维生素的还有维生素D（又称钙化醇）、维生素E（又称生育酚）和维生素K（又称凝血维生素）；另一类是水溶性维生素，主要是B族维生素（主要包括B1、B2、B3、B6、B12）、维生素C（又称抗坏血酸）、维生素PP（又称尼克酸）、维生素H（又称生物素）和维生素M（又称叶酸）等。\n\n植物来源的β-胡萝卜素及其他胡萝卜素可在人体内合成维生素A，β-胡萝卜素的转换效率最高。在体内，在β-胡萝卜素-15，15′-双氧酶（双加氧酶）催化下，可将β-胡萝卜素转变为两分子的视黄醛（ratinal），视黄醛在视黄醛还原酶的作用下还原为视黄醇。但β - 胡萝卜素也可以合成虾青素（astaxanthin，强抗氧化剂），但是只有武汉大学药学院黄泽波教授在实验室研究操作，到试产阶段还得假以时日。","过量可能引起关节痛，呕吐，头痛，精神错乱","缺乏维生素A，会使上皮细胞的功能减退，导致皮肤弹性下降，干燥，粗糙，失去光泽","鸡肉，牛肉，土豆，燕麦基于谷类，番茄制品，肝脏，肾，蛋黄和粗粮")
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
       
        
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func leftNavClick(sender: AnyObject) {
        
        self.navigationController?.popViewControllerAnimated(true)
    }
    
    func getContentHight(section:Int)->CGFloat{
        
        let contentSize = CGSize(width: view.frame.width - 24, height: 1000)
        
        var str = ""
        switch(section){
        
        case 1:
            str = recommendContent.summary
        case 2:
            str = recommendContent.over
        case 3:
            str = recommendContent.lack
        case 4:
            str = recommendContent.suply
        default:
            break
        }
        
        let attribute = [NSFontAttributeName:UIFont.systemFontOfSize(14.0),NSForegroundColorAttributeName:UIColor.blackColor()]
        
        let needSize:CGRect = str.boundingRectWithSize(contentSize, options: OCUtils.combine(), attributes: attribute , context: nil)
        
        return needSize.size.height + 80
    }

    // MARK: - Table view data source
    
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
          tableView.deselectRowAtIndexPath(indexPath, animated: true)
    }

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 5
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 1
    }
    
    override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 1
    }
    override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 10
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        
       
        
        switch indexPath.section{
        
        case 0:
            return 75
        case 1,2,3,4:
            return getContentHight(indexPath.section)
            
        default:
            return 0
        }
    }

    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let identifier = indexPath.section == 0 ? "elementNavCell" : "summaryCell"
        let cell = tableView.dequeueReusableCellWithIdentifier(identifier, forIndexPath: indexPath)

        switch indexPath.section{
        
        case 0:
            break
        case 1:
            (cell as? RecommendTableViewCell)?.titleStr = "简介"
            (cell as? RecommendTableViewCell)?.contentStr = recommendContent.summary
        case 2:
            (cell as? RecommendTableViewCell)?.titleStr = "过量反应"
            (cell as? RecommendTableViewCell)?.contentStr = recommendContent.over
        case 3:
            (cell as? RecommendTableViewCell)?.titleStr = "缺乏"
            (cell as? RecommendTableViewCell)?.contentStr = recommendContent.lack
        case 4:
            (cell as? RecommendTableViewCell)?.titleStr = "补充"
            (cell as? RecommendTableViewCell)?.contentStr = recommendContent.suply
            
        default:
            break
        }

        return cell
    }
    

    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the specified item to be editable.
        return true
    }
    */

    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            // Delete the row from the data source
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        } else if editingStyle == .Insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }
    */

    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the item to be re-orderable.
        return true
    }
    */

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
